local dingzhen = fk.CreateSkill {
  name = "gai__dingzhen",
}

Fk:loadTranslationTable{
  ["gai__dingzhen"] = "定镇",
  [":gai__dingzhen"] = "每轮开始时，你可以令与你距离X以内的任意名其他角色依次选择一项（X为你当前体力值）：" ..
  "1.弃置一张【杀】；2.本轮其于回合内使用锦囊牌不能指定你为目标。",

  ["#gai__dingzhen-choose"] = "定镇：你可以令至多%arg名角色选择一项",
  ["#gai__dingzhen-discard"] = "定镇：弃一张【杀】，否则本轮回合内使用锦囊牌不能指定 %src 为目标",
  ["@@gai__dingzhen-round"] = "定镇",

  ["$gai__dingzhen1"] = "招抚流民，兴复县邑。",
  ["$gai__dingzhen2"] = "容民畜众，群羌归土。",
}

dingzhen:addEffect(fk.RoundStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(dingzhen.name) and
      table.find(player.room:getOtherPlayers(player, false), function(p)
        return p:compareDistance(player, player.hp, "<=")
      end) and player.hp > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local n = player.hp
    local targets = table.filter(room:getOtherPlayers(player, false), function(p)
      return p:compareDistance(player, n, "<=")
    end)
    local tos = room:askToChoosePlayers(player, {
      targets = targets,
      min_num = 1,
      max_num = #targets,
      prompt = "#gai__dingzhen-choose:::" .. #targets,
      skill_name = dingzhen.name,
    })
    if #tos > 0 then
      room:sortByAction(tos)
      event:setCostData(self, { tos = tos })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = event:getCostData(self).tos or {}
    for _, p in ipairs(targets) do
      if not p.dead and
        #room:askToDiscard(p, {
          min_num = 1,
          max_num = 1,
          pattern = "slash",
          prompt = "#gai__dingzhen-discard:" .. player.id,
          skill_name = dingzhen.name,
        }) == 0 and not player.dead then
        room:addTableMarkIfNeed(p, "@@gai__dingzhen-round", player.id)
      end
    end
  end,
})

dingzhen:addEffect("prohibit", {
  is_prohibited = function(self, from, to, card)
    return from and card and to and
      Fk:currentRoom():getCurrent() == from and card.type == Card.TypeTrick and
      table.contains(from:getTableMark("@@gai__dingzhen-round"), to.id)
  end,
})

return dingzhen

  